package ${package}.controller;
import java.util.List;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import pro.shuangxi.core.base.controller.BaseController;
import pro.shuangxi.core.base.query.QueryWrapper;
import pro.shuangxi.core.base.vo.Result;
import org.apache.commons.lang3.StringUtils;
import ${package}.entity.${TableName};
import ${package}.service.${TableName}Service;
/**
* @author ${author}
* @since ${date}
* @description：${tableComment!}
*/
@RestController
@RequestMapping("/${tableName}")
public class ${TableName}Controller{

@Autowired
protected ${TableName}Service ${tableName}Service;
@GetMapping("page")
public Result page(Pageable page, ${TableName} pojo) {
QueryWrapper<${TableName}> queryWrapper = new QueryWrapper<>();
<#list  columns as field>
    <#if field.javaType=="String">
        if (StringUtils.isNotBlank(pojo.get${field.ColumnName!}())) {
        queryWrapper.like("${field.columnName!}", pojo.get${field.ColumnName!}());
        }
    </#if>
</#list>

Page<${TableName}> pageData = this.${tableName}Service.page(page,queryWrapper);
return Result.OK(pageData);
}


@PostMapping("upsert")
public Result upsert(@RequestBody ${TableName} pojo) {
${TableName} ${tableName} = this.${tableName}Service.saveOrUpdate(pojo);
return Result.OK(${tableName});
}

@DeleteMapping("remove")
public Result remove(String ids) {
if (StringUtils.isBlank(ids)) {
return Result.ERR("ids is require");
}
String[] idArray = ids.split(",");
Long[] idsLongArray = new Long[idArray.length];
for (int i = 0; i < idArray.length; i++) {
idsLongArray[i] = Long.valueOf(idArray[i]);
}
this.${tableName}Service.deleteByIds(idsLongArray);
return Result.OK("ok");
}

@GetMapping("getById")
public Result getById(Long id) {
${TableName} byId = this.${tableName}Service.getById(id);
return Result.OK(byId);
}

@GetMapping("list")
public Result list() {
List<${TableName}> all = this.${tableName}Service.getAll();
    return Result.OK(all);
}

}
